package menuaction.jasperTools;

import java.util.Map;

/**
 * klasa zawiera parametry potrzebne RunJasperRaportMenuAction do wystartowanai raportu
 * @author looser
 *
 */
public class JasperRunnerParams 
{
	private String jrxmlFile;
	private String xmlFile;
	private String recEditName;
	private String raportName;
	private Map<String,Object> params;
	
	/**
	 * 
	 * @param jrxmlFile sciezka do pliku .jrxml
	 * @param xmlFile sciezka do pliku, w ktorym zdefiniowana jest edytka do pobierania parametrow wydruku
	 * @param recEditName nazwa recEdita
	 * @param params parametry,ktore zostana przekazane jasperowi
	 */
	public JasperRunnerParams(String jrxmlFile, String xmlFile,
			String recEditName,Map<String,Object> params,String raportName) {
		super();
		this.jrxmlFile = jrxmlFile;
		this.xmlFile = xmlFile;
		this.recEditName = recEditName;
		this.params = params;
		this.raportName = raportName;
	}

	public String getRaportName()
	{
		return raportName;
	}
	public void setRaportName(String raportName)
	{
		this.raportName=raportName;
	}
	
	public String getJrxmlFile() {
		return jrxmlFile;
	}

	public void setJrxmlFile(String jrxmlFile) {
		this.jrxmlFile = jrxmlFile;
	}

	public String getXmlFile() {
		return xmlFile;
	}

	public void setXmlFile(String xmlFile) {
		this.xmlFile = xmlFile;
	}

	public String getRecEditName() {
		return recEditName;
	}

	public void setRecEditName(String recEditName) {
		this.recEditName = recEditName;
	}

	public Map<String, Object> getParams() {
		return params;
	}

	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

	/**
	 * Metoda dokona konwersji typow.<br> 
	 * Bedzie parsowala wszystkie stringi z wartoscami na typy zdefiniowane w paramach raportu w xmlu<br>
	 * @param record rekord,ktory ma zostac zparsowany
	 * @return
	 */
	public void setCParams(Map<String, String> record) 
	{
		String[] keys = record.keySet().toArray(new String[0]); 
		for(int i=0;i<keys.length;++i)
		{
			Object ob = params.get(keys[i]);
			if(ob instanceof String)
			{
				params.put(keys[i], record.get(keys[i]));
			}
			else if(ob instanceof Double)
			{
				params.put(keys[i], Double.parseDouble(record.get(keys[i])));
			}
			else if(ob instanceof Integer)
			{
				params.put(keys[i], Integer.parseInt(record.get(keys[i])));
			}
		}
	}
}
